/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 *  \file     Sent_Etimer_Types.h                                                                           *
 *  \brief    This file contains interface header for CAN MCAL driver, ...                             *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2025/02/14     <td>1.0.0                               *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifndef SENTETIMER_TYPES_H
#define SENTETIMER_TYPES_H

#include "Std_Types.h"

typedef uint8 SentEtimer_ChannelType;

typedef void(*SentEtimer_FrameOverNotifType)(void);

/**
 * @enum SentEtimer_HwModule
 * @brief Timer module index id
*/
typedef enum {
    SENTETIMER_INDEX_ETIMER1 = 0U,
    SENTETIMER_INDEX_ETIMER2 = 1U,
    SENTETIMER_INDEX_ETIMER3 = 2U,
    SENTETIMER_INDEX_ETIMER4 = 3U,
} SentEtimer_HwModule;

/**
 * @enum SentEtimer_HwChannel
 * @brief Timer module hardware Channel id
*/
typedef enum {
    SENTETIMER_HW_CPT_A  = 0U,
    SENTETIMER_HW_CPT_B  = 1U,
    SENTETIMER_HW_CPT_C  = 2U,
    SENTETIMER_HW_CPT_D  = 3U
} SentEtimer_HwChannel;

/**
 * @enum SentEtimer_State
 * @brief Sent frame current status
*/
typedef enum {
    SENTETIMER_IDLE = 0U,
    SENTETIMER_SYNC,
    SENTETIMER_STATUS,
    SENTETIMER_DATA,
    SENTETIMER_CRC,
    SENTETIMER_PAUSE
} SentEtimer_State;

/**
 * @enum SentEtimer_ErrType
 * @brief Sent frame current error
*/
/* PRQA S 1535 20 */
typedef enum {
    SENTETIMER_OK             = 0UL,
    SENTETIMER_SYNC_ERR       = (1UL << 0U),   /*! @brief Sync/Calibration pulse is not 56 ticks. */
    SENTETIMER_STATUS_ERR     = (1UL << 1U),   /*! @brief Status signal error. */
    SENTETIMER_DATA_ERR       = (1UL << 2U),   /*! @brief Nibble data is bigger than 15. */
    SENTETIMER_CRC_ERR        = (1UL << 3U),   /*! @brief Nibble data is bigger than 15. */
    SENTETIMER_LOW_PULSE_ERR  = (1UL << 4U),   /*! @brief Nibble low pulse width error. */
    SENTETIMER_MSB_NOT_ZERO   = (1UL << 5U),   /*! @brief SENTETIMER_HIGH_SPEED_FORMAT Only. */
    SENTETIMER_INV_MSN_ERR    = (1UL << 6U),   /*! @brief SENTETIMER_SINGLE_SECURE_FORMAT Only. */
    SENTETIMER_CONUNTER_VAL_ERR = (1UL << 7U), /*! @brief SENTETIMER_SINGLE_SECURE_FORMAT Only. */
    SENTETIMER_TICK_FREQ_ERR  = (1UL << 8U),   /*! @brief SENTETIMER_SINGLE_SECURE_FORMAT Only. */
    /*PRQA S 0646  1*/
    SENTETIMER_NOT_OK         = (1UL << 31U),  /*! @brief SENTETIMER_SINGLE_SECURE_FORMAT Only. */
} SentEtimer_ErrType;

/**
 * @enum SentEtimer_FastChannelType
 * @brief Fast Channel Format Type
*/
typedef enum {
    SENTETIMER_STANDARD_FORMAT = 0U,
    SENTETIMER_SINGLE_SECURE_FORMAT,
    SENTETIMER_HIGH_SPEED_FORMAT
} SentEtimer_FastChannelType;

/**
 * @enum SentEtimer_BitNum
 * @brief Sent message section length
*/
typedef enum {
    SENTETIMER_DATA_WIDTH_4_BIT = 1,
    SENTETIMER_DATA_WIDTH_8_BIT,
    SENTETIMER_DATA_WIDTH_12_BIT,
    SENTETIMER_DATA_WIDTH_16_BIT,
    SENTETIMER_DATA_WIDTH_20_BIT,
    SENTETIMER_DATA_WIDTH_24_BIT,
} SentEtimer_BitNum;

typedef enum {
    SENTETIMER_SAE_J2716_2008,
    SENTETIMER_SAE_J2716_2010
} SentEtimer_Crc4Mode;

/**
 * @enum SentEtimer_Frame
 * @brief Sent Frame Format Type
*/
typedef struct {
    uint8 u8Dl;              /*! @brief Sent Frame message length */
    uint8 u8RxIndex;         /*! @brief Sent Frame current message index */
    uint8 u8Status;          /*! @brief Sent Frame status section value */
    uint8 u8Rxframe[6];      /*! @brief Sent Frame message section */
    uint8 u8Crc;             /*! @brief Sent Frame CRC section */
} SentEtimer_Frame;

typedef struct {
    SentEtimer_Frame FrameInfo;  /*! @brief Sent frame infomation */
    SentEtimer_FastChannelType eChnFormat; /*! @brief Sent Channel format */
    SentEtimer_State eCurstate;  /*! @brief Sent Channel current status */
    uint32 eError;     /*! @brief Sent Channel current error infomation */
    boolean bReadFlag;  /*! @brief Sent Channel current newest status */
} SentEtimer_Channel;

/**
 * @struct SentEtimer_CounterScaler
 * @brief Sent_Scaler value
*/
typedef struct {
    uint32 u32ExpectScaler;       /*! @brief Theoretical calculation Tick prescaler*/
    uint32 u32ActualScaler;       /*! @brief Actual synchronization segment Tick prescaler*/
} SentEtimer_CounterScaler;

/**
 * @struct SentEtimer_HwChannelConfigType
 * @brief Hardware Channel descriptions
*/
typedef struct {
    SentEtimer_HwModule u8TimerModule;            /*! @brief Timer module ID ,0-1: Timer 0/1*/
    SentEtimer_HwChannel u8HwChannel;             /*! @brief SENT hw channel ID,2-5:LOCAL_A/B/C/D */
    SentEtimer_FastChannelType eFastChannel;      /*! @brief Fast Channel Format Type*/
    SentEtimer_BitNum eDataBitNum;                /*! @brief Data bit number*/
    uint8 u8LowPulseWid;                    /*! @brief Low Pulse Width*/
    uint8 u8FifoWml;                        /*! @brief Fifo water mark level */
    boolean bFiterEnable;                   /*! @brief software fiter function enable */
    uint8 u8SampleInterval;                 /*! @brief fiter function fiter interval clock */
    uint8 u8FiterBandwidth;                 /*! @brief fiter function fiter negedge capture bandwidth */
    boolean bPausePulse;                    /*! @brief Pause Pulse */
    boolean bNotifyFrameOver;               /*! @brief FrameOverNotification function enable*/
    SentEtimer_FrameOverNotifType pfFrameOverNotification; /*! @brief FrameOverNotification function pointer */
    SentEtimer_Crc4Mode crc4Select;
} SentEtimer_HwChannelConfigType;

/**
 * @struct SentEtimer_ChannelConfigType
 * @brief This type contains logic channel config data.
*/
typedef struct {
    uint32 u32TickFrequency;            /*! @brief Transmitter frequency */
    const SentEtimer_HwChannelConfigType *SentHwChannelConfig;        /*! @brief hardware channel config */
} SentEtimer_ChannelConfigType;

/**
 * @struct SentEtimer_ConfigType
 * @brief This type contains initialization data.
*/
typedef struct {
    const SentEtimer_ChannelConfigType (*ptrChannelConfig)[];
} SentEtimer_ConfigType;

#endif /* SENTETIMER_TYPES_H */
/* End of file */
